#include "CShellExeHelper.h"

CImpersonateLoggedOnUser g_ImpersonateLoggedOnUser;

CImpersonateLoggedOnUser::CImpersonateLoggedOnUser()
{

}

void CImpersonateLoggedOnUser::Init()
{
	auto activeSID = WTSGetActiveConsoleSessionId();

	if (WTSQueryUserToken(activeSID, &m_hTokerUser))
	{
		m_bImpersonateLoggedOnUser = ImpersonateLoggedOnUser(m_hTokerUser);
		//CloseHandle(m_hTokerUser);
	}
	DWORD ec = GetLastError();
	ec += 1;
}

CImpersonateLoggedOnUser::~CImpersonateLoggedOnUser()
{
	if (m_bImpersonateLoggedOnUser)
	{
		RevertToSelf();
	}
	if (m_hTokerUser)
	{
		CloseHandle(m_hTokerUser);
	}
}
